package org.stvd.repository.workflow.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.stvd.core.dto.QueryResult;
import org.stvd.entities.workflow.WfGroup;
import org.stvd.repository.base.impl.BaseDaoImpl;
import org.stvd.repository.workflow.WfGroupDao;

@Repository("WfGroupDao")
public class WfGroupDaoImpl extends BaseDaoImpl<WfGroup> implements WfGroupDao {

    @Override
    public QueryResult<WfGroup> wfGroupQuery(int start, int limit, String name, String code, String createUid) {
        String hql = "FROM WfGroup WHERE 1=1 "
            + " AND (name like ?0 OR '' like ?0)"	
            + " AND (code = ?1 OR '' = ?1)"
            + " AND (createUid = ?2 OR '' = ?2) "
            + " ORDER BY modifyTime DESC";
        return getQueryResultByHQL(start, limit, hql, "%"+name+"%", code, createUid);
    }

    @Override
    public List<WfGroup> listWfGroupByCondition(String code, String status) {
        String hql = "FROM WfGroup WHERE (code = ?0 or '' = ?0) ADN (status = ?1 or '' = ?1)";
        return findByHQL(hql, code, status);
    }
    
    @Override
    public WfGroup getWfGroupByCode(String code) {
        List<WfGroup> list = findByHQL("FROM WfGroup WHERE code = ?0 ", code);
        if(list!=null && list.size() > 0){
            return list.get(0);
        }
        return null;
    }
}
